;Layer on/off/freeze/thaw tool keyed to CLG fields.
;
;	AUTHOR: HENRY C. FRANCIS
;		425 N. ASHE ST.
;		SOUTHERN PINES, NC 28387
;              
;		All rights reserved without prejudice.
;	Copyright:	7-10-94
;	Edited:		7-10-94
;
(defun c:clgentof (/); entla lname lfun clgm nstr 
  (if lflt nil (setq lflt ""))
  (if lfco nil (setq lfco ""))
  (if ltstr nil (setq ltstr "-"))
  (if costr nil (setq costr "?"))
  (if mjstr nil (setq mjstr "?"))
  (if mnstr nil (setq mnstr "????"))
  (if mdstr nil (setq mdstr "????"))
(cond
  ((and(eq ullt "Y")(not(eq ulco "Y")))
    (setq lflt "Linetype, "
          lfco "")
    (princ (strcat "\nOnly Layers also with Linetype of selection will be modified.")))
  ((and(eq ulco "Y")(not(eq ullt "Y")))
    (setq lflt ""
          lfco "Color, ")
    (princ (strcat "\nOnly Layers also with Color of selection will be modified.")))
  ((and(eq ullt "Y")(eq ulco "Y"))
    (setq lflt "Linetype, "
          lfco "Color, ")
    (princ (strcat "\nOnly Layers also with Linetype and Color of selection will be modified.")))
  ((and(not(eq ullt "Y"))(not(eq ulco "Y")))
    (setq lflt ""
          lfco "")
    (princ (strcat "\nLayer Linetype and Layer Color will not be considered.")))
);cond
  (cond 
    ((eq (substr clgm 4) "o")
      (setq lfun "off")
      (setq lfmsg "turned off"))
    ((eq (substr clgm 4) "f")
      (setq lfun "freeze")
      (setq lfmsg "frozen"))
    ((eq (substr clgm 4) "n")
      (setq lfun "on")
      (setq lfmsg "turned on"))
    ((eq (substr clgm 4) "t")
      (setq lfun "thaw")
      (setq lfmsg "thawed"))
);cond
(cond
    ((eq (substr clgm 1 3) "maj")
      (setq lfpat (strcat "Major, " lflt lfco)))
    ((eq (substr clgm 1 3) "min")
      (setq lfpat (strcat lflt "Minor, " lfco)))
    ((eq (substr clgm 1 3) "mod")
      (setq lfpat (strcat lflt lfco "Modifier, ")))
    ((eq (substr clgm 1 3) "mmc")
      (setq lfpat (strcat "Major, " lflt "Minor, " lfco)))
    ((eq (substr clgm 1 3) "mnc")
      (setq lfpat (strcat "Major, " lflt "Minor, " lfco "Modifier, ")))
    ((eq (substr clgm 1 3) "maj")
      (setq lfpat (strcat lflt "Minor, " lfco "Modifier, ")))
  );cond
(if
  (or(eq(substr clgm 4)"o")(eq(substr clgm 4)"f"))
(while
  (setq entla (entsel (strcat "\nSelect entity for layer " lfpat lfun)))
  (setq lname (cdr (assoc 8 (entget (car entla)))))
  (cond ((eq (substr clgm 1 3) "maj")
          (setq nstr (strcat(substr lname 1 1)(if(eq ullt "Y")(substr lname 2 1)"?")"????"(if(eq ulco "Y")(substr lname 7 1)"?")"*")))
        ((eq (substr clgm 1 3) "min")
          (setq nstr (strcat "?"(if(eq ullt "Y")(substr lname 2 1)"?")(substr lname 3 4)(if(eq ulco "Y")(substr lname 7 1)"?")"*")))
        ((eq (substr clgm 1 3) "mod")
          (setq nstr (strcat "?"(if(eq ullt "Y")(substr lname 2 1)"?")"????"(if(eq ulco "Y")(substr lname 7 1)"?")(substr lname 8 4) "*")))
        ((eq (substr clgm 1 3) "mmc")
          (setq nstr (strcat (substr lname 1 1)(if(eq ullt "Y")(substr lname 2 1)"?")(substr lname 3 4)(if(eq ulco "Y")(substr lname 7 1)"?")"*")))
        ((eq (substr clgm 1 3) "mnc")
          (setq nstr (strcat(substr lname 1 1)(if(eq ullt "Y")(substr lname 2 1)"?")(substr lname 3 4)(if(eq ulco "Y")(substr lname 7 1)"?")(substr lname 8 4)"*")))
        ((eq (substr clgm 1 3) "nmc")
          (setq nstr (strcat "?"(if(eq ullt "Y")(substr lname 2 1)"?")(substr lname 3 4)(if(eq ulco "Y")(substr lname 7 1)"?")(substr lname 8 4)"*")))
  );cond
);while
);if
(if
  (or(eq(substr clgm 4)"o")(eq(substr clgm 4)"f"))
  nil
(cond
  ((and(eq ullt "Y")(not(eq ulco "Y")))
    (setq ltstr (ustr 1 "Enter Layer Linetype Character (1)" ltstr nil))
    (setq costr "?"))
  ((and(eq ulco "Y")(not(eq ullt "Y")))
    (setq ltstr "?")
    (setq costr (ustr 1 "Enter Layer Color Character (1)" costr nil)))
  ((and(eq ullt "Y")(eq ulco "Y"))
    (setq ltstr (ustr 1 "Enter Layer Linetype Character (1)" ltstr nil))
    (setq costr (ustr 1 "Enter Layer Color Character (1)" costr nil)))
  ((and(not(eq ullt "Y"))(not(eq ulco "Y")))
    (setq ltstr "?")
    (setq costr "?"))
);cond
);if
(cond ((or(eq clgm "majn")(eq clgm "majt"))
        (setq mjstr (strcat(ustr 1 "Enter CLG Major Group Character (1)" mjstr nil)))
        (setq nstr (strcat mjstr ltstr "????" costr "*")))
      ((or(eq clgm "minn")(eq clgm "mint"))
        (setq mnstr (strcat(ustr 1 "Enter CLG Minor Group Characters (4)" mnstr nil)))
        (setq nstr (strcat "?" ltstr mnstr costr "*")))
      ((or(eq clgm "modn")(eq clgm "modt"))
        (setq mdstr (strcat(ustr 1 "Enter CLG Modifier Characters (4)" mdstr nil)))
        (setq nstr (strcat "?" ltstr "????" costr mdstr "*")))
      ((or(eq clgm "mmcn")(eq clgm "mmct"))
        (setq mjstr (ustr 1 "Enter CLG Major Group Character (1)" mjstr nil))
        (setq mnstr (ustr 1 "Enter CLG Minor Group Characters (4)" mnstr nil))
        (setq nstr (strcat mjstr ltstr mnstr costr "*")))
      ((or(eq clgm "mncn")(eq clgm "mnct"))
        (setq mjstr (ustr 1 "Enter CLG Major Group Character (1)" mjstr nil))
        (setq mnstr (ustr 1 "Enter CLG Minor Group Characters (4)" mnstr nil))
        (setq mdstr (ustr 1 "Enter CLG Modifier Characters (4)" mdstr nil))
        (setq nstr (strcat mjstr ltstr mnstr costr mdstr "*")))
      ((or(eq clgm "nmcn")(eq clgm "nmct"))
        (setq mnstr (ustr 1 "Enter CLG Minor Group Characters (4)" mnstr nil))
        (setq mdstr (ustr 1 "Enter CLG Modifier Characters (4)" mdstr nil))
        (setq nstr (strcat "?" ltstr mnstr costr mdstr "*")))
);cond
  (setq xprt (getvar"expert"))
  (setvar "expert" 5)
  (setq cmde (getvar"cmdecho"))
  (setvar "cmdecho" 0)
  (command ".layer" lfun nstr "")
  (setvar "cmdecho" cmde)
  (setvar "expert" xprt)
  (prompt (strcat "Layer names " nstr " have been " lfmsg))
  (princ)
);defun
